package com.example.pc.updata.DaTi;

import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.pc.http.API;
import com.example.pc.http.Okhttp;
import com.example.pc.updata.Baes.BaseActivity;
import com.example.pc.updata.R;
import com.example.pc.updata.obj.FanKui;
import com.example.pc.updata.tools.MyBaseAdapter;
import com.example.pc.utils.JSONUtils;
import com.example.pc.view.MyListView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;


public class FanKuiListActivity extends BaseActivity {

    @BindView(R.id.btn_back)
    ImageView btnBack;
    @BindView(R.id.my_list)
    MyListView myList;
    List<FanKui.DataBean> list_timu = new ArrayList<FanKui.DataBean>();
    MyBaseAdapter<FanKui.DataBean> myBaseAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fan_kui_list);
        ButterKnife.bind(this);
        findAll();
        btnBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        myBaseAdapter = new MyBaseAdapter<FanKui.DataBean>(FanKuiListActivity.this, R.layout.item_ly_2, list_timu) {
            @Override
            protected void initialData(int position, View converView, ViewGroup arg2) {
                TextView tv = (TextView) converView.findViewById(R.id.tv_text);
                TextView tv2 = (TextView) converView.findViewById(R.id.tv_text2);
                FanKui.DataBean fanKui = getList().get(position);
                tv.setText("用户:" + fanKui.getUser());
                tv2.setText("反馈内容:" + getList().get(position).getComment());

            }
        };
        myList.setAdapter(myBaseAdapter);
    }

    private void findAll() {
        API.getcomments(new Okhttp.Objectcallback() {
            @Override
            public void onsuccess(String st) {
                FanKui fanKui = JSONUtils.parseJSON(st, FanKui.class);
                if (fanKui.getData() != null && fanKui.getData().size() > 0) {
                    myBaseAdapter.setList(fanKui.getData());
                    myBaseAdapter.notifyDataSetChanged();
                } else {

                }

            }

            @Override
            public void onFalia(int code, String errst) {

            }
        });
//        BmobQuery<FanKui> categoryBmobQuery = new BmobQuery<>();
//        categoryBmobQuery.findObjects(new FindListener<FanKui>() {
//            @Override
//            public void done(List<FanKui> list, BmobException e) {
//                if (e == null) {
//                    if (!list.isEmpty() && list.size() > 0) {
//                        myBaseAdapter.setList(list);
//                        myBaseAdapter.notifyDataSetChanged();
//                    } else {
//                    }
//                } else {
//
//                }
//            }
//        });
    }
}
